#include <common.h>
#include <command.h>
#include <syscon.h>
#include <env.h>
#include <asm/io.h>
#include <asm/arch/stm32.h>

#define SYSCFG_BOOTR            0x00

static int do_stm32boot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
    u8 *syscfg;
    u32 bootr;
    char bootpin[2];

    syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
    bootr = readl(syscfg + SYSCFG_BOOTR);

    snprintf(bootpin, sizeof(bootpin), "%d", bootr&7);
    printf("Boot pin status: %s\n", bootpin);
    env_set("bootpin", bootpin);

    return 0;
}

U_BOOT_CMD(
    stm32boot, 1, 1, do_stm32boot,
    "Check STM32 BOOT pins status",
    "This command get the status of BOOT pins and set bootpin environment."
);

